pkgname=chanchantv-svn
_appname=chanchantv
pkgver=53
pkgrel=1
pkgdesc="An online streaming TV app for watching your favorite channels"
url="http://chanchantv.googlecode.com"
arch=('i686' 'x86_64')
license="GPL2"
depends=('python2' 'python2-pyqt')
optdepends=('sopcast: sopcast streaming support')
makedepends=('subversion')

_svntrunk=http://chanchantv.googlecode.com/svn/trunk/
_svnmod=chanchantv

md5sums=()
source=()

build() {
    export PYTHON="/usr/bin/python2"
    
    if [ -d $_svnmod/.svn ]; then
	    (cd $_svnmod && svn up -r $pkgver)
    else
	    #svn co --depth empty $_svntrunk --config-dir ./ -r $pkgver $_svnmod
            svn co $_svntrunk --config-dir ./ -r $pkgver $_svnmod
    fi

    msg "SVN checkout done or server timeout"
    msg "Packaging $pkgname..."	

  rm -rf "$srcdir/$_svnmod-build"
  #find . -type f -not -name "*chanchan*" -exec rm {} \;
  cp -r "$srcdir/$_svnmod" "$srcdir/$_svnmod-build"

}

package() {
  cd "$srcdir/$_svnmod-build"

  install -d "${pkgdir}/usr/"{bin,share}

  cp -r "$srcdir/$_appname" "${pkgdir}/usr/share/"

  sed -i '1s/python$/python2/' "$pkgdir"/usr/share/chanchantv/chanchan.py
  find "$pkgdir" -type d -name '\.svn' -exec rm -rf {} +

  install -Dm644 "$pkgdir/usr/share/chanchantv/$_appname.png" "$pkgdir/usr/share/pixmaps/$_appname.png"
  install -Dm644 "$pkgdir/usr/share/chanchantv/$_appname.desktop" "$pkgdir/usr/share/applications/$_appname.desktop"

  cat > "$pkgdir/usr/bin/chanchantv" <<'EOF'
#!/bin/bash
cd /usr/share/chanchantv/
python2 ./chanchan.py 
exit 0
EOF
  chmod +x "$pkgdir/usr/bin/chanchantv"
  ln -s "$pkgdir/usr/bin/chanchantv" "$pkgdir/usr/bin/tv"
}
